package com.example.shuiyin.controller;

import com.example.shuiyin.dto.ApiResponse;
import com.example.shuiyin.dto.system.SystemSettingsResponse;
import com.example.shuiyin.dto.system.SystemStatsResponse;
import com.example.shuiyin.service.SystemService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/system")
@RequiredArgsConstructor
public class SystemController {

    private final SystemService systemService;

    @GetMapping("/settings")
    public ResponseEntity<ApiResponse<SystemSettingsResponse>> getSettings() {
        return ResponseEntity.ok(ApiResponse.success("获取系统设置成功", systemService.getSettings()));
    }

    /**
     * 获取系统统计信息 (仅管理员)
     */
    @GetMapping("/stats")
    @PreAuthorize("hasRole('ADMIN')")
    public ResponseEntity<ApiResponse<SystemStatsResponse>> getStats(@RequestAttribute("userId") Long userId) {
        log.info("管理员[{}]获取系统统计信息", userId);
        return ResponseEntity.ok(ApiResponse.success("获取系统统计信息成功", systemService.getStats()));
    }
} 